<%@page import="com.alibaba.fastjson.JSONArray"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.general.Util"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/mobile/plugin/westvalley/common/jsp/scriptEncoderCommon.jsp" %>
<%
String workflowId = Util.null2String(request.getParameter("workFlowId"));
String nodeId = Util.null2String(request.getParameter("nodeId"));
String scriptsList = Util.null2String(request.getParameter("scripts"));
String scriptsTag = "";
JSONArray arr = null;
if(!"".equals(scriptsList)){
	arr = JSONArray.parseArray(scriptsList);
	if(arr!=null){
		for(Object obj : arr){
			if(obj!=null){
				JSONObject json = (JSONObject)obj;
				String src = Util.null2String(json.getString("src"));
				if( !"".equals(src) ){
					scriptsTag += "<script type=\"text/javascript\" src=\""+src+"\"></script>\n";
				}
			}
		}
	}
}
String scripts = "";
RecordSet rs = new RecordSet();
String sql = "select scripts from workflow_nodehtmllayout where workflowid = '"+workflowId+"' and nodeid = '"+nodeId+"'";
rs.executeSql(sql);
if(rs.next()){
	scripts = scriptDecode(Util.null2String(rs.getString("scripts")));
	int beginIndex = scripts.indexOf("<!--beginScript-->");
	int endIndex = scripts.indexOf("<!--endScript-->");
	if(beginIndex>=0 && endIndex>0){
		StringBuffer sb = new StringBuffer(scripts);
		String beginStringBuffer = sb.substring(0,beginIndex);
		String endStringBuffer = sb.substring(endIndex+"<!--endScript-->".length());
		scripts = beginStringBuffer+"\n<!--beginScript-->\n"+scriptsTag+"\n<!--endScript-->\n"+endStringBuffer;
	}else{
		scripts += "\n<!--beginScript-->"+"\n"+scriptsTag+"\n<!--endScript-->\n";
	}
}

String updateSql = "update workflow_nodehtmllayout set scripts = ? where workflowid = ? and nodeid = ?";
System.out.println(scripts);
boolean flag = rs.executeUpdate(updateSql,scriptEncode(scripts),workflowId,nodeId);
JSONObject json = new JSONObject();
json.put("flag",flag);
out.print(json.toJSONString());
%>
